package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.model.task.TaskProgress;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class TaskProgressViewBinder extends ItemViewBinder<TaskProgress, TaskProgressViewBinder.ViewHolder> {

    private static final int TYPE_TOP = 0x0002;

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_task_progress, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull TaskProgress taskProgress) {
        holder.mTvDate.setText(taskProgress.getBilldate());
        holder.mTvContent.setText(taskProgress.getPerson() + ":" + taskProgress.getContent());

        if(holder.getAdapterPosition() == TYPE_TOP){
            holder.mTvTopLine.setVisibility(View.INVISIBLE);
            holder.mTvDot.setBackgroundResource(R.drawable.timelline_dot_first);
        }
        if(holder.getAdapterPosition() == getAdapter().getItemCount() - 1){
            holder.mTvBottomLine.setVisibility(View.INVISIBLE);
        }else{
            holder.mTvBottomLine.setVisibility(View.VISIBLE);
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvTopLine;
        TextView mTvDot;
        TextView mTvBottomLine;
        TextView mTvDate;
        TextView mTvContent;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvTopLine = itemView.findViewById(R.id.tvTopLine);
            mTvDot = itemView.findViewById(R.id.tvDot);
            mTvBottomLine = itemView.findViewById(R.id.tvBottomLine);
            mTvDate = itemView.findViewById(R.id.tvDate);
            mTvContent = itemView.findViewById(R.id.tvContent);
        }
    }

    @Override
    protected long getItemId(@NonNull TaskProgress item) {
        return super.getItemId(item);
    }
}
